package fr.babostesting.examples.mobile.bench 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.PixelSnapping;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageQuality;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Matrix;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import fr.babos.core.entries.Document;
	import fr.babos.graphic.components.controls.text.Label;
	import fr.babos.graphic.components.controls.text.TextSkin;
	import net.hires.debug.Stats;
	
	/**
	 * Bench sur les perfs des bitmaps en mode GPU
	 * @author ZoulouX
	 */
	public class BitmapBench2 extends Document
	{
		private var _bitmapData:BitmapData;
		private var _bitmap:Bitmap;
		private var _matrix:Matrix;
		
		protected var _label:Label;
		
		public function BitmapBench2 ()
		{
			
		}
		
		override public function init ():void
		{
			_bitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0xFFFFFFFF);
			_bitmap = new Bitmap(_bitmapData, PixelSnapping.NEVER, false);
			
			_bitmap.width = stage.stageWidth;
			_bitmap.height = stage.stageHeight;
			
			stage.quality = StageQuality.LOW;
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			stage.autoOrients = false;
			
			addChild(_bitmap);
			addChild(new Stats());
			
			_label = new Label(false, false);
			_label.size(stage.stageWidth - 10, 20);
			_label.textSkin(new TextSkin( {
				font: "Arial",
				size: 14,
				color: 0
			}, null, false, AntiAliasType.ADVANCED));
			
			_matrix = new Matrix();
			_matrix.translate(5, 3);
			
			stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
		
		protected var _increment:int;
		protected var _scrollStep:int;
		protected var _speed:int = 3;
		
		protected function enterFrameHandler (event:Event):void
		{
			_bitmapData.lock();
			
			_bitmapData.scroll(0, _speed);
			
			_scrollStep += _speed;
			
			if (_scrollStep == 30)
			{
				_scrollStep = 0;
				
				_label.text(Math.random() + " " + Math.random() + " " + Math.random());
				
				if ("drawWithQuality" in _bitmapData)
					_bitmapData.drawWithQuality(_label, _matrix, null, null, null, true, StageQuality.HIGH);
				else
					_bitmapData.draw(_label, _matrix, null, null, null, true);
			}
			
			_bitmapData.unlock();
		}
	}
}